home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / workbench / datatypes / playdt13.lha / PlayDT / PlayDT-src / UseAsl.c < prev    next >
C/C++ Source or Header  |  1997-06-05  |  4KB  |  179 lines

  1. /****************************************************************
  2.  *
  3.  * $VER: UseAsl.c 1.3 (4.6.97) Tak Tang (tst92@ecs.soton.ac.uk)
  4.  *
  5.  * Copyright © 1997 Tak Tang
  6.  *
  7.  * You may use any part of this source code in your own programs
  8.  * provided that it is not called PlayDT.
  9.  *
  10.  *****************************************************************/
  11.  
  12.  
  13. /**** Soft definitions ****/
  14.  
  15. #define ASM             __asm __saveds
  16. #define REG(x)          register __ ## x
  17.  
  18.  
  19. /**** Header files ****/
  20.  
  21. #include "PlayDT.h"
  22.  
  23. #include <libraries/asl.h>
  24.  
  25. #include <workbench/startup.h>
  26.  
  27. #include <datatypes/datatypesclass.h>
  28.  
  29. #include <clib/asl_protos.h>
  30. #include <clib/dos_protos.h>
  31. #include <clib/exec_protos.h>
  32. #include <clib/datatypes_protos.h>
  33.  
  34. #include <pragmas/asl_pragmas.h>
  35. #include <pragmas/dos_pragmas.h>
  36. #include <pragmas/exec_pragmas.h>
  37. #include <pragmas/datatypes_pragmas.h>
  38.  
  39.  
  40. /**** Forward declarations ****/
  41.  
  42. ULONG ASM Filter (REG (a0) struct Hook *,
  43.       REG (a2) struct FileRequester *, REG (a1) struct AnchorPath *);
  44.  
  45.  
  46. /****** UseASL *****************************************************
  47. *
  48. *   NAME
  49. *       UseASL - use a file requester, and call PlayFile for files selected
  50. *
  51. *   SYNOPSIS
  52. *       UseASL ( GlobalData )
  53. *
  54. *       UseASL ( struct GlobalData * );
  55. *
  56. *   FUNCTION
  57. *       UseASL will open an ASL file requester to prompt the user for
  58. *       sound files to play.  The requester supports patterns,
  59. *       multiselect, and a datatypes filter, that ensures that only
  60. *       directories and sound files appear in the requester.
  61. *
  62. *       UseAsl will keep opening the file requester until the user
  63. *       selects cancel, or there is a problem.
  64. *
  65. *   INPUTS
  66. *       GlobalData -
  67. *
  68. *   RESULT
  69. *
  70. *   EXAMPLE
  71. *
  72. *   NOTES
  73. *       All errors are reported via IntuiError
  74. *
  75. *   BUGS
  76. *
  77. *   SEE ALSO
  78. *       UseCli.c/UseCli(), UseWB.c/UseWB(), UseWB.c/IntuiError()
  79. *
  80. *****************************************************************************
  81. *
  82. */
  83.  
  84.  
  85. void UseASL(struct GlobalData *gd)
  86. {
  87.   struct Library *AslBase;
  88.   struct FileRequester *fr;
  89.   struct Hook filter;
  90.   BPTR newlock;
  91.   BPTR oldlock;
  92.   struct WBArg *args;
  93.   ULONG i;
  94.  
  95.   if (AslBase = OpenLibrary ("asl.library", 38L))
  96.   {
  97.     filter.h_Entry = (HOOKFUNC)Filter;
  98.     fr = AllocAslRequestTags ( ASL_FileRequest,
  99.          ASLFR_TitleText,      "Select Sound to Play",
  100.          ASLFR_PositiveText,   "Play",
  101.          ASLFR_DoMultiSelect,  TRUE,
  102.          ASLFR_DoPatterns,     TRUE,
  103.          ASLFR_FilterFunc,     &filter,
  104.          ASLFR_RejectIcons,    TRUE,
  105.          TAG_DONE );
  106.     if ( NULL != fr )
  107.     {
  108.       while ( (FALSE==gd->UserStop) && AslRequest(fr, NULL) )
  109.       {
  110.         if (fr->rf_NumArgs)
  111.         {
  112.           newlock = Lock (fr->rf_Dir, ACCESS_READ);
  113.           if ( NULL != newlock )
  114.           {
  115.             oldlock=CurrentDir(newlock);
  116.             args = fr->rf_ArgList;
  117.             for ( i=fr->rf_NumArgs; (i--) && (FALSE==gd->UserStop) ;args++ )
  118.             {
  119.               if ( PlayFile(gd, args->wa_Name) )
  120.               {
  121.                 IntuiError( gd, args->wa_Name );
  122.               } /* if error */
  123.             } /* for each argument */
  124.             CurrentDir(oldlock);
  125.             UnLock(newlock);
  126.           } /* if Lock() OK */
  127.           else
  128.           {
  129.             IntuiError( gd, fr->rf_Dir );
  130.           } /* if Lock() FAIL */
  131.  
  132.         } /* if NumArgs>0 */
  133.       } /* while ASLRequest() OK */
  134.       FreeAslRequest (fr);
  135.     } /* if NULL!=fr */
  136.     else
  137.     {
  138.       IntuiError( gd, "AllocAslRequest()" );
  139.     } /* if NULL==fr */
  140.  
  141.     if (AslBase) CloseLibrary(AslBase);
  142.   } /* if OpenLibrary(Asl) OK */
  143.   else
  144.   {
  145.     IntuiError( gd, "OpenLibrary()" );
  146.   } /* if OpenLibrary(Asl) failed */
  147. } /* UseASL() */
  148.  
  149.  
  150. /**** Filter() ****/
  151.  
  152. ULONG ASM Filter (REG (a0) struct Hook *h, REG (a2) struct FileRequester *fr, REG (a1) struct AnchorPath *ap)
  153. {
  154.   struct DataType *dtn;
  155.   ULONG use = FALSE;
  156.   BPTR flock, dlock, olock;
  157.  
  158.   if ( dlock = Lock(fr->fr_Drawer, ACCESS_READ) ) {
  159.     olock=CurrentDir(dlock);
  160.     if ( flock = Lock(ap->ap_Info.fib_FileName, ACCESS_READ) )
  161.     {
  162.       if ( dtn = ObtainDataTypeA (DTST_FILE, (APTR) flock, NULL) )
  163.       {
  164.         if (dtn->dtn_Header->dth_GroupID == GID_SOUND) use = TRUE;
  165.         ReleaseDataType (dtn);
  166.       } /* if ObtainDataTypeA() OK */
  167.       UnLock (flock);
  168.     } /* if Lock(file) OK */
  169.     CurrentDir(olock);
  170.     UnLock(dlock);
  171.   } /* if Lock(Directory) OK */
  172.  
  173.   return (use);
  174. } /* Filter() */
  175.  
  176.  
  177. /**** End of file ****/
  178.  
  179.